package com.sugar.base.core;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

@Repository
public class Test_JdbcBaseDaoSupport extends JdbcBaseCore {
	

	public void loademp() {
		/*this.getJdbcTemplate().query("select *from sugar_department", new ResultSetExtractor(){

			@Override
			public Object extractData(ResultSet rs) throws SQLException,
					DataAccessException {
				while(rs.next()) {
					System.out.println(rs.getString(1));
				}
				return null;
			}
		}) ;*/
		
		
		try {
			Connection conn = this.getDataSource().getConnection() ;
			
			//创建CallableStatement对象
			CallableStatement cs = conn.prepareCall("{call p_paging(?,?,?,?,?,?)}") ;
			cs.setString(1, "sugar_employee") ;
			cs.setInt(2, 3);
			cs.setInt(3, 5);
			cs.registerOutParameter(4, oracle.jdbc.driver.OracleTypes.INTEGER) ;
			cs.registerOutParameter(5, oracle.jdbc.driver.OracleTypes.INTEGER) ;
			cs.registerOutParameter(6, oracle.jdbc.driver.OracleTypes.CURSOR) ;
			
			cs.execute() ;
			
			//总记录数
			String myrows = cs.getString(4) ;
			//总页数
			int mypageCount = cs.getInt(5) ;
			
			System.out.println("总记录数："+myrows);
			System.out.println("总页数："+mypageCount);
			
			ResultSet rs = (ResultSet) cs.getObject(6) ;
			while(rs.next()) {
				System.out.println("员工编号："+rs.getString(1) 
						+"  员工名称："+rs.getString(2) 
						+ "   员工职位："+rs.getString(3));
			}
			conn.close() ;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
	}
	
	public static void main(String[] args) {
		
		
		ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bean.xml") ;
		
		Test_JdbcBaseDaoSupport h = (Test_JdbcBaseDaoSupport) ctx.getBean("test_JdbcBaseDaoSupport") ;
		
		h.loademp() ;
		
	}
	
	
}
